package week02;

import org.apache.hadoop.io.Writable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

public class TrafficRecord implements Writable {
    private String phoneNumber;
    private Long bytesUp ;
    private Long bytesDown ;
    private Long byteSum;
    public TrafficRecord(){
    }
    public TrafficRecord(String up,String down){
        bytesUp = Long.valueOf(up);
        bytesDown = Long.valueOf(down);
        byteSum = bytesUp + bytesDown;
    }

    public TrafficRecord(long up, long down){
        bytesUp = up;
        bytesDown = down;
        byteSum = up + down;
    }

    public TrafficRecord(String phone, long up, long down){
        phoneNumber = phone;
        bytesUp = up;
        bytesDown = down;
        byteSum = up + down;
    }

    public Long getBytesUp() {
        return bytesUp;
    }

    public Long getBytesDown() {
        return bytesDown;
    }

    public Long getByteSum() {
        return byteSum;
    }

    @Override
    public void write(DataOutput dataOutput) throws IOException {
        dataOutput.writeString(phoneNumber);
        dataOutput.writeLong(bytesUp);
        dataOutput.writeLong(bytesDown);
        dataOutput.writeLong(byteSum);
    }

    @Override
    public void readFields(DataInput dataInput) throws IOException {
        phoneNumber = dataInput.readString();
        bytesUp = dataInput.readLong();
        bytesDown = dataInput.readLong();
        byteSum = dataInput.readLong();
    }

    public String toString(){
        return String.format("%s\t%d\t%d\t%d",phoneNumber,bytesUp,bytesDown,byteSum);
    }
}
